#ifndef __WINDOW_H__
#define __WINDOW_H__

#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <gdk/gdkkeysyms.h> 
#include "./contact_handler.h"
#include "../network/servent.h"

// settaggi per la dimensione della finestra di chat
#define WINDOW_W 1000
#define WINDOW_H 500

// Numero massimo di chat_room che possono essere aperte concorrentemente
#define MAX_ROOM 5

// Oggetti per la gestione della main windows
GtkWidget *main_window;
GtkWidget *button1;
GtkWidget *entry_chat;
GtkWidget *main_box;
GtkWidget *entry_status;

// Oggetto per la gestione della chat window
typedef struct{
	gchar * chat_name;
	GtkWidget *chat_window;
	GtkWidget *hpaned;
	GtkWidget *c_text_area; 
	GtkWidget *m_text_area;
	GtkTextBuffer *m_buffer;
	GtkTextBuffer *c_buffer ;
	GtkWidget *contact_list;
} chat_room;

chat_room room[MAX_ROOM];

// struttura per la gestione dei meta dati della contanct list
enum{
	USER_ID,
	USER_NAME,
	USER_STATUS,
	N_COLUMNS
};

// enum{
// 	CHAT,
//  	C_COLUMNS
// };

//funzioni principali per la gestione del'intefaccia grafica
void init_gui(int argc, char *argv[]);
pthread_t gui_hndl;
#define draw_gui_th()	pthread_create(&gui_hndl, NULL, draw_gui, NULL);
void draw_gui();

//funzioni per il disegno degli oggetti grafici
void draw_chat_window();
void draw_main_window();

//gestione contatti
void add_contact(const gchar *chat, const gchar *user_id, const gchar *user_name, const gchar *status);
void rem_contact_from_all_chat(const gchar *user_id);
void rem_contact(const gchar *chat, const gchar *user_id);
gchar* get_contact_from_name(const gchar *chat, const gchar *user_name);
void update_contact_status(const gchar *user_id, const gchar *status);
gint update_personal_status(GtkWidget *widget, GdkEventKey *event);
void rem_all_contacts(gchar * chat);

//gestione dei messaggi
void incoming_message(const gchar *chat, const char*user_id, const char *user_name, const char* user_status, const char *message);
void draw_message(chat_room *cr, const char *chars);
gint send_message(GtkWidget *widget, GdkEventKey *event, chat_room *cr);

//utility
void clear_chat();
int check_joined_chat(gchar* chat);

//gestione della chat
gint join(GtkWidget *widget, GdkEvent *event);
gint leave(GtkWidget *widget, chat_room *cr);

//gestione utente locale
gchar* get_personal_status();
gchar* get_personal_user_name();
gchar* get_personal_user_id();

#endif
